//
//  GGDataBase.m
//  TestAppDelegateService
//
//  Created by yuemei on 2017/9/21.
//  Copyright © 2017年 yuemei. All rights reserved.
//

#import "GGDataBase.h"
#import <YYKit/YYKit.h>

static NSString *const GGDataBaseCacheKey = @"GGDataBaseCacheKey";

@interface GGDataBase()
@property (nonatomic, strong) YYCache *cacheManager;
@end

@implementation GGDataBase

static GGDataBase *_dataBase = nil;
+ (instancetype)shareDataBase{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _dataBase = [[GGDataBase alloc] init];
    });
    return _dataBase;
}

- (void)setCacheWithData:(id)data Key:(NSString *)key{
    [self.cacheManager setObject:data forKey:key];
}


- (void)setMemoryCacheWithData:(id)data Key:(NSString *)key{
    [self.cacheManager.memoryCache setObject:data forKey:key];
}

- (id)getCacheForKey:(NSString *)key{
    return [self.cacheManager objectForKey:key];
}

- (id)getMemoryCacheForKey:(NSString *)key{
    return [self.cacheManager.memoryCache objectForKey:key];
}

- (void)removeCacheWithKey:(NSString *)key{
    [self.cacheManager removeObjectForKey:key];
}

- (void)removeAllCache{
    [self.cacheManager.diskCache removeAllObjects];
}

- (NSInteger)getAllCacheSize{
    return [self.cacheManager.diskCache totalCost];
}




#pragma mark - setter&getter

-(YYCache *)cacheManager{
    if (!_cacheManager) {
        _cacheManager = [YYCache cacheWithName:GGDataBaseCacheKey];
    }
    return _cacheManager;
}
@end
